<template>
  <!-- 作业票审查 经办 -->
  <view v-if="listData.length === 0"><empty></empty></view>
  <view v-else>
    <view class="cu-card-wrap" v-for="(item, index) in listData" :key="item.nodeTaskId">
      <view class="header-wrap">
        <view class="title-wrap">
          <image class="icon" src="/static/images/gkicon1.png" mode="aspectFit"></image>
          <text class="title">停/送电作业</text>
        </view>
      </view>
      <view class="body-wrap">
        <view class="content-wrap">
          <view class="label"> 作业票编号：</view>
          <view class="value">{{ item.ticketCode }}</view>
        </view>
        <view class="content-wrap">
          <view class="label">分厂：</view>
          <view class="value">{{ item.areaName }}</view>
        </view>
        <view class="content-wrap">
          <view class="label">工段/区域：</view>
          <view class="value">{{ item.secondFactoryName }}</view>
        </view>
        <view class="content-wrap">
          <view class="label">电压：</view>
          <view class="value">{{ item.electricNum + item.electricUnit }}</view>
        </view>
        <view class="content-wrap">
          <view class="label">当前状态：</view>
          <view class="value">{{ item.statusLabel }}</view>
        </view>
        <view class="content-wrap">
          <view class="label">待办人：</view>
          <view class="value">{{ item.currentUserNames }}</view>
        </view>
        <view class="content-wrap">
          <view class="label">作业票证：</view>
          <navigator :url="`/pages/jobSlip/power-cut/detail?ticketId=${item.ticketId}`" class="value color-88B4C4">
            查看详情
          </navigator>
        </view>
      </view>
      <view class="footer-wrap" style="justify-content: flex-end">
        <view class="button-wrap">
          <navigator :url="getUrl(item)" class="button"> 处理 </navigator>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import Empty from '@/components/cu-empty/index.vue'
import { getElectricTodoList } from '@/api/spw/powerCut.js'
export default {
  components: {
    Empty
  },
  data() {
    return {
      listData: [],
      pageNum: 1,
      pageSize: 10,
      total: null,
      isFinished: false
    }
  },
  onShow() {
    this.initData()
  },
  onPullDownRefresh() {
    this.initData()
  },
  onReachBottom() {
    this.pageNum++
    this.getList()
  },
  methods: {
    getUrl(item) {
      switch (item.status) {
        case '1': //停电审核
        case '6': //送电审核
          return `/pages/jobSlip/power-cut/flow/examine?ticketId=${item.ticketId}`
        case '2': //停电审批
        case '7': //送电审批
          return `/pages/jobSlip/power-cut/flow/approve?ticketId=${item.ticketId}` //停送电审批
        case '4': //待停电
        case '8': //待送电
          return `/pages/jobSlip/power-cut/flow/confirm?ticketId=${item.ticketId}` //停送电确认
        // case '5': //停电作业中
        // case '9': //送电申请退回
        //return `/pages/jobSlip/power-cut/flow/start?ticketId=${item.ticketId}`; //送电申请
        case '3': //重新申请
          return `/pages/jobSlip/power-cut/flow/applyFor?ticketId=${item.ticketId}`
      }
    },
    initData() {
      this.listData = []
      this.isFinished = false
      this.pageNum = 1
      this.pageSize = 10
      this.total = null
      this.getList()
    },
    getList() {
      if (this.isFinished) {
        return
      }
      const data = {
        pageSize: 10,
        pageNum: this.pageNum
      }
      if (!this.total || this.total > this.listData.length) {
        getElectricTodoList(data)
          .then((res) => {
            if (this.pageNum === 1) {
              this.listData = res.rows
            } else {
              this.listData.push(...res.rows)
            }
            this.total = res.total
          })
          .finally(() => {
            uni.stopPullDownRefresh()
          })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.cu-card-wrap {
  margin-bottom: 24rpx;
}
</style>
